#include "musiclist.h"
#include<QMimeDatabase>
MusicList::MusicList()
{

}

void MusicList::addMusicUrl(const QList<QUrl>& musicUrls)
{
    //将所有的音乐文件放入musicList中
   for(auto e:musicUrls)
   {
       //检测musicUrl是否是一个有效的歌曲文件，检测文件的MIME类型
       QMimeDatabase mimeDB;
       QMimeType mimeType=mimeDB.mimeTypeForFile(e.toLocalFile());
       QString musicType=mimeType.name();
       //audio/mpeg  audio/flac  audio/wav
       if(musicType=="audio/mpeg"||musicType=="audio/flac"||musicType=="audio/wav")
       {
       //构造音乐对象
       Music music(e);
       musicList.push_back(music);
       }
   }
}

iterator MusicList::findMusicByMusicId(const QString &musicId)
{
   for(auto it=begin();it!=end();++it)
   {
       if(it->getMusicUuid()==musicId)
           return it;
   }
   return end();
}

iterator MusicList::begin()
{
    return musicList.begin();
}

iterator MusicList::end()
{
    return musicList.end();
}
